/*********************************************************************
 * PoolTest.java created on Feb 2, 2010
 *
 * This file is part of Sure Tech Support Portal System. 
 * Copyright @ 2010 Sure Tech (HK) Limited. All rights reserved.
 * Sure Tech PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 *********************************************************************/
package com.bizdigger.db.pool;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @Author: Mac Wang
 * @Date: Feb 2, 2010 3:00:20 PM 
 * @Email: mac@suretech.com.hk
 */

public class PoolTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws SQLException {
		SecObjectPool pool = new SecObjectPool();
		Connection connection = null;
		try
		{
			connection = (Connection)pool.borrowObject();
			PreparedStatement ps = null;
			ps = connection.prepareStatement("select * from role");
			ResultSet rs = ps.executeQuery();
			rs.close();
			
			System.out.println("================");
			
			pool.addObject();
			System.out.println("使用中几个：" + pool.getNumActive());
			System.out.println("队列中还有：" + pool.getNumIdle());
			
			pool.addObject();
			pool.addObject();
			pool.addObject();
			pool.addObject();
			
			connection = (Connection)pool.borrowObject();
			connection = (Connection)pool.borrowObject();
			connection = (Connection)pool.borrowObject();
			
			pool.addObject();
			pool.addObject();
			pool.addObject();
			pool.addObject();
			
			System.out.println("使用中几个：" + pool.getNumActive());
			System.out.println("队列中还有：" + pool.getNumIdle());
			
			System.out.println("================");
			
			pool.returnObject(connection);
			
			System.out.println("使用中几个：" + pool.getNumActive());
			System.out.println("队列中还有：" + pool.getNumIdle());
			
			System.out.println("=====clear===========");
			
			pool.clear();
			System.out.println("=====close===========");
			pool.close(); 
		}
		catch(Throwable e)
		{
			e.printStackTrace();
			connection.close();
		}
	}
}
